<?xml version="1.0" encoding="UTF-8"?>
<!--

       Copyright 2006-2016 the original author or authors.

       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.

-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Running MyBatis Generator With Ant</title>
    <link rel="stylesheet" type="text/css" href="../mbgstyle.css"/>
</head>
<body>
<h1>Running MyBatis Generator With Ant</h1>
<p>MyBatis Generator (MBG) includes a simple Ant task. The task must be defined in your
    build.xml file, and the task accepts several parameters. Here is an example
    build.xml file:</p>
<pre>
   &lt;project default="genfiles" basedir="."&gt;
     &lt;property name="generated.source.dir" value="${basedir}" /&gt;

     &lt;target name="genfiles" description="Generate the files"&gt;
       &lt;taskdef name="mbgenerator"
                classname="org.mybatis.generator.ant.GeneratorAntTask"
                classpath="mybatis-generator-core-x.x.x.jar" /&gt;
       &lt;mbgenerator overwrite="true" configfile="generatorConfig.xml" verbose="false" &gt;
         &lt;propertyset&gt;
           &lt;propertyref name="generated.source.dir"/&gt;
         &lt;/propertyset&gt;
       &lt;/mbgenerator&gt;
     &lt;/target&gt;
   &lt;/project&gt;
</pre>

<p>MyBatis Generator task attributes are as follows:</p>
<table border="1" cellspacing="0" cellpadding="5">
    <tr>
        <th>Attribute</th>
        <th>Value</th>
    </tr>
    <tr>
        <td>configfile (required)</td>
        <td>Specifies the name of the configuration file.</td>
    </tr>
    <tr>
        <td>overwrite (optional)</td>
        <td>If "true", "yes", etc., then MBG will overwrite existing Java files if an existing Java
            file if found with the same name as a generated file. If "false", "no", etc., and a
            Java file already exists with the same name as a generated file, then MBG
            will write the newly generated Java file to the proper directory with a
            unique name (e.g. MyClass.java.1, MyClass.java.2, etc.).
            <b>Important: MBG will always merge and overwrite XML files.</b></td>
    </tr>
    <tr>
        <td>contextids (optional)</td>
        <td>If specified, then this is a comma delimited list of contexts to use in
            the current run. Any id specified in the list must exactly
            match the value of the <code>id</code> attribute of an
            &lt;context&gt; configuration element. Only ids specified
            in this list will be active for this run. If this argument
            is not specified, then all contexts will be active.
        </td>
    </tr>
    <tr>
        <td>tables (optional)</td>
        <td>If specified, then this is a comma delimited list of tables to use in
            the current run. Any table specified in the list must exactly
            match the fully qualified table name specified in a
            &lt;table&gt; configuration element. Only tables specified
            in this list will be active for this run. If this argument
            is not specified, then all tables will be active.
            Specify table names as: <br/><br/>
            <code>table</code><br/>
            <code>schema.table</code><br/>
            <code>catalog..table</code><br/>
            etc.
        </td>
    </tr>
    <tr>
        <td>verbose (optional)</td>
        <td>If "true", "yes", etc., then MBG will log progress messages to the
            ant console (if Ant is running in verbose mode). The default is "false".
        </td>
    </tr>
</table>

<p>Notes:</p>
<ul>
    <li>The classpath on the &lt;taskdef&gt; is used to tell Ant where the MBG JAR file
        is. This is optional if you add MBG to the Ant classpath in one
        of the other ways described in the Ant manual
    </li>
    <li>The name of the task can be anything you desire, "mbgenerator" is
        simply an example
    </li>
    <li>The task supports an optional nested <code>&lt;propertyset&gt;</code> element which
        is the standard Ant property set type. This can be used to pass parameters into
        a configuration file. For example, the above property
        <code>generated.source.dir</code> can be
        accessed in the configuration file with the escape sequence
        <code>${generated.source.dir}</code>
    </li>
    <li>If a property is specified in the configuration file and is not resolved,
        then the escaped property string will be passed "as is" into the generated code.
    </li>
</ul>
</body>
</html>